package com.qfmy.webapp.service.impl.common;

import com.qfmy.model.entity.common.MemberPackage;
import com.qfmy.model.vo.common.MemberPackageVo;
import com.qfmy.webapp.mapper.common.MemberPackageMapper;
import com.qfmy.webapp.service.common.MemberPackageService;
import org.jetbrains.annotations.Contract;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @author 清风明月
 * @Package com.qfmy.webapp.service.impl.common
 * @date 2025/11/12
 * @description 会员
 */
@Service
public class MemberPackageServiceImpl implements MemberPackageService {

    /**
     * 注入mapper
     */
    @Autowired
    private MemberPackageMapper memberPackageMapper;


    /**
     * 获取会员
     * @return
     */
    @Override
    public List<MemberPackageVo> getMemberPackage() {
        //获取会员
        List<MemberPackage> memberPackage = memberPackageMapper.getMemberPackage();
        //转换vo
        return convertToVo(memberPackage);
    }

    /**
     * 转换vo
     * @param memberPackage
     * @return
     */
    @NotNull
    @Contract(pure = true)
    private List<MemberPackageVo> convertToVo(List<MemberPackage> memberPackage) {
        //创建 vo集合
        List<MemberPackageVo> memberPackageVos = new ArrayList<>();
        if (memberPackage != null) {
           for (MemberPackage mp : memberPackage)
           {
               //创建 vo
               MemberPackageVo memberPackageVo = new MemberPackageVo();
               //对象拷贝
               BeanUtils.copyProperties(mp, memberPackageVo);
               memberPackageVos.add(memberPackageVo);
           }
        }
        return memberPackageVos;
    }
}
